home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / other / python-1.52 / lib / python1.5 / copy_reg.py < prev    next >
Text File  |  1999-06-14  |  501b  |  22 lines

  1. # Helper to provide extensibility for pickle/cPickle.
  2.  
  3. dispatch_table = {}
  4. safe_constructors = {}
  5.  
  6. def pickle(ob_type, pickle_function, constructor_ob = None):
  7.     dispatch_table[ob_type] = pickle_function
  8.  
  9.     if constructor_ob is not None:
  10.         constructor(constructor_ob)
  11.  
  12. def constructor(object):
  13.     safe_constructors[object] = 1
  14.  
  15. # Example: provide pickling support for complex numbers.
  16.  
  17. def pickle_complex(c):
  18.     return complex, (c.real, c.imag)
  19.  
  20. pickle(type(1j), pickle_complex, complex)
  21.  
  22.